package com.yzkj.cpjxc.business.domain;

import com.yzkj.cpjxc.business.framework.utils.DateTimeUtils;
import com.yzkj.cpjxc.business.constants.SysLogConstants;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.ibatis.type.Alias;

import java.util.Date;

/**系统日志
 */
@Alias("SysLog")
public class SysLog extends CommonBean<SysLog> {

	private static final long serialVersionUID = -704337061681856900L;

	/**
	 * 主键
	 */
	private String logId;

	/**
	 * IP地址
	 * */
	private String ip;

	/**
	 * 请求地址
	 */
	private String requestUrl;

	/**
	 * 用户操作的中文翻译
	 */
	private String opeContent;

	/**
	 * 用户传递的参数名称和值
	 */
	private String paramValues;

	/**
	 * 操作人
	 */
	private String operationUsername;

	/**
	 * 日志类型 1：正常操作日志    2：错误日志
	 */
	private Integer logType;

	/**
	 * 操作动作(C 新增 U 修改 D 删除）
	 */
	private String operationAction;

	/**
	 * 异常信息
	 */
	private String exMsg;

	/**
	 * 异常信息位置:定位到具体类.方法  行数
	 */
	private String errLocation;

	/**
	 * 操作时间
	 */
	private Date operationTime;
	
	// ================================================================================================================================================
	
	/**
	 * 日志类型名称
	 */
	public String getLogTypeName() {
		if (this.getLogType() == null) {
			return "";
		}
		return SysLogConstants.getLogTypeMap().get(this.getLogType());
	}
	
	/**
	 * 操作动作名称
	 */
	public String getOperationActionName() {
		if (StringUtils.isBlank(this.getOperationAction())) {
			return "";
		}
		return SysLogConstants.getOperActionMap().get(this.getOperationAction());
	}
	
	// ================================================================================================================================================

	public String getLogId() {
		return logId;
	}

	public void setLogId(String logId) {
		this.logId = logId;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public String getRequestUrl() {
		return requestUrl;
	}

	public void setRequestUrl(String requestUrl) {
		this.requestUrl = requestUrl;
	}

	public String getOpeContent() {
		return opeContent;
	}

	public void setOpeContent(String opeContent) {
		this.opeContent = opeContent;
	}

	public String getParamValues() {
		return paramValues;
	}

	public void setParamValues(String paramValues) {
		this.paramValues = paramValues;
	}

	public String getOperationUsername() {
		return operationUsername;
	}

	public void setOperationUsername(String operationUsername) {
		this.operationUsername = operationUsername;
	}

	public Integer getLogType() {
		return logType;
	}

	public void setLogType(Integer logType) {
		this.logType = logType;
	}

	public String getOperationAction() {
		return operationAction;
	}

	public void setOperationAction(String operationAction) {
		this.operationAction = operationAction;
	}

	public String getExMsg() {
		return exMsg;
	}

	public void setExMsg(String exMsg) {
		this.exMsg = exMsg;
	}

	public String getErrLocation() {
		return errLocation;
	}

	public void setErrLocation(String errLocation) {
		this.errLocation = errLocation;
	}

	public Date getOperationTime() {
		return operationTime;
	}

	public void setOperationTime(Date operationTime) {
		this.operationTime = operationTime;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((errLocation == null) ? 0 : errLocation.hashCode());
		result = prime * result + ((exMsg == null) ? 0 : exMsg.hashCode());
		result = prime * result + ((ip == null) ? 0 : ip.hashCode());
		result = prime * result + ((logId == null) ? 0 : logId.hashCode());
		result = prime * result + ((logType == null) ? 0 : logType.hashCode());
		result = prime * result + ((opeContent == null) ? 0 : opeContent.hashCode());
		result = prime * result + ((operationAction == null) ? 0 : operationAction.hashCode());
		result = prime * result + ((operationTime == null) ? 0 : operationTime.hashCode());
		result = prime * result + ((operationUsername == null) ? 0 : operationUsername.hashCode());
		result = prime * result + ((paramValues == null) ? 0 : paramValues.hashCode());
		result = prime * result + ((requestUrl == null) ? 0 : requestUrl.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SysLog other = (SysLog) obj;
		if (errLocation == null) {
			if (other.errLocation != null)
				return false;
		} else if (!errLocation.equals(other.errLocation))
			return false;
		if (exMsg == null) {
			if (other.exMsg != null)
				return false;
		} else if (!exMsg.equals(other.exMsg))
			return false;
		if (ip == null) {
			if (other.ip != null)
				return false;
		} else if (!ip.equals(other.ip))
			return false;
		if (logId == null) {
			if (other.logId != null)
				return false;
		} else if (!logId.equals(other.logId))
			return false;
		if (logType == null) {
			if (other.logType != null)
				return false;
		} else if (!logType.equals(other.logType))
			return false;
		if (opeContent == null) {
			if (other.opeContent != null)
				return false;
		} else if (!opeContent.equals(other.opeContent))
			return false;
		if (operationAction == null) {
			if (other.operationAction != null)
				return false;
		} else if (!operationAction.equals(other.operationAction))
			return false;
		if (operationTime == null) {
			if (other.operationTime != null)
				return false;
		} else if (!operationTime.equals(other.operationTime))
			return false;
		if (operationUsername == null) {
			if (other.operationUsername != null)
				return false;
		} else if (!operationUsername.equals(other.operationUsername))
			return false;
		if (paramValues == null) {
			if (other.paramValues != null)
				return false;
		} else if (!paramValues.equals(other.paramValues))
			return false;
		if (requestUrl == null) {
			if (other.requestUrl != null)
				return false;
		} else if (!requestUrl.equals(other.requestUrl))
			return false;
		return true;
	}

	@Override
	public String toString() {
		String operationTimeStr = (operationTime != null ? DateFormatUtils.format(operationTime, DateTimeUtils.sdfyyyyMMddHHmmss) : "");
		if (SysLogConstants.LOG_TYPE_ERROR.equals(this.getLogType())) {
			return "SysLog [logId=" + logId + ", ip=" + ip + ", requestUrl=" + requestUrl + ", opeContent=" + opeContent + ", paramValues=" + paramValues + ", operationUsername="
					+ operationUsername + ", logType=" + this.getLogTypeName() + ", operationAction=" + this.getOperationActionName() + ", exMsg=" + exMsg + ", errLocation=" + errLocation + ", operationTime="
					+ operationTimeStr + "]";
		} else {
			return "SysLog [logId=" + logId + ", ip=" + ip + ", requestUrl=" + requestUrl + ", opeContent=" + opeContent + ", paramValues=" + paramValues + ", operationUsername="
					+ operationUsername + ", logType=" + this.getLogTypeName() + ", operationAction=" + this.getOperationActionName() + ", operationTime="
					+ operationTimeStr + "]";
		}
	}

}
